// page/usageRecord/usageRecord.js
const http = require('../../../utils/http');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    items: [],
    animationData: '',
    showModalStatus: '',
    statid: '', //卡状态,
    typeid: '', //卡类型
    perpage: 10, //每页数据条
    page: 1,

  },
  typeid(e) {
    //卡类型选择筛选
    this.setData({
      typeid: e.currentTarget.dataset.id
    })
  },
  status(e) {
    //卡状态选择筛选
    this.setData({
      statid: e.currentTarget.dataset.id
    })
  },
  // 筛选
  getnewid() {
    //获取卡管理列表数据
    http.postRequest('/mini/v1/vip/list', {
      type_id: this.data.typeid,
      status: this.data.statid
    }, res => {
      if (res.msg == 'ok') {
        if (this.page && this.status) {
          let {
            data
          } = res.data
          if (res.data.data.length) {
            let newarr = this.data.items
            newarr.push(...data)
            this.setData({
              items: newarr,
              perpage: this.data.perpage,
              page: this.data.page + 1
            })
          } else {
            wx.showToast({
              title: '我是有底线的',
              icon: 'none',
              duration: 1500
            })
          }

        } else {
          let {
            data
          } = res.data
          this.setData({
            items: data,
          })
        }
      }
    })
    this.hideModal()
  },

  getlist(page, status) {
    //获取卡管理列表数据
    http.postRequest('/mini/v1/vip/list', {
      type_id: this.data.typeid,
      per_page: this.data.perpage,
      page: this.data.page,
      status: this.data.statid
    }, res => {
      if (res.msg == 'ok') {
        if (page && status) {
          let {
            data
          } = res.data
          if (res.data.data.length) {
            let newarr = this.data.items
            newarr.push(...data)
            this.setData({
              items: newarr,
              perpage: this.data.perpage,
              page: this.data.page + 1
            })
          } else {
            wx.showToast({
              title: '我是有底线的',
              icon: 'none',
              duration: 1500
            })
          }

        } else {
          let {
            data
          } = res.data
          this.setData({
            items: data,
          })
        }
      }
    })
  },
  //点击我显示底部弹出框
  clickme: function () {
    this.showModal();
  },

  //显示对话框
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  //隐藏对话框
  closeModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },

  newCard() {
    wx.navigateTo({
      url: '/pages/openCard/openCard/openCard',
    })
  },
  //跳到卡详情
  jumpCardDetail(e) {
    let vipid = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/openCard/cardCopy/cardCopy?vip=' + vipid,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getlist()
    //获取卡管理列表
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getlist(1, 1)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})